#include <iostream>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>

using std::cout;
using std::endl;

void fun()
{
    int fds[2];
    pipe(fds);
    pid_t pid = fork();
    if(pid == 0){
        close(fds[0]);
        write(fds[1], "hello parent, i am your child!", 31);
        printf("i am child, write: \n");
        close(fds[1]);
    }else{
        close(fds[1]);
        char buf[32]{0};
        read(fds[0], buf, 31);
        close(fds[0]);
        printf("i am parent, recv: %s\n", buf);
        wait(NULL);
    }
}

int main(int args, char *argv[])
{
    fun();
    return 0;
}